/*
 * @Author: your name
 * @Date: 2020-04-10 17:00:18
 * @LastEditTime: 2020-05-13 13:32:09
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \cellProject\src\modules\Front\router\index.js
 */
// 加载vue-router
import Router from 'vue-router'
// 导入全局vue路由
const _import = file => () => import('@/modules/front/pages/' + file + '.vue')

// 配置路由
export const constantRouterMap = [
  { path: '/404', component: () => import('@components/Error/404') },
  { path: '/index', component: _import('Home/index') },
  { path: '*', redirect: '/404' },
  { path: '', redirect: '/index' }
]

// 创建router
export default new Router({
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (!from.meta.noCache) {
        from.meta.savedPosition =
          document.body.scrollTop ||
          document.documentElement.scrollTop ||
          window.pageYoffset
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  },
  routes: constantRouterMap
})

// 全局路由定义
export const asyncRouterMap = []
